#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// Q2. 统计特殊三元组
// https://leetcode.cn/contest/weekly-contest-454/problems/count-special-triplets/description/

class Solution {
    int mod = 1000000007;

public:
    int specialTriplets(vector<int>& nums) {
        unordered_map<int, unordered_set<int>> recordCountOfNum;
        for (int i = 0; i < nums.size(); i++)
        {
            recordCountOfNum[nums[i]].insert(i);
        }
        long long ans = 0;
        for (int i = 0; i < nums.size() - 2; i++)
        {
            int curNum = nums[i];
            recordCountOfNum[curNum].erase(i);
            if(recordCountOfNum[curNum].empty()){
                continue;
            }
            if (curNum % 2 != 0)
            {
                continue;
            }
            int target = curNum / 2;
            if(recordCountOfNum.find(target) == recordCountOfNum.end()){
                continue;
            }
            for(auto it : recordCountOfNum[target]){
                for(auto numIt : recordCountOfNum[curNum]){
                    if(numIt > it){
                        ans = (ans + 1) % mod;
                    }
                }
            }
        }
        return ans;
    }
};

int main()
{
    return 0;
}